package com.coinworld.admin.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSenderImpl;

import java.security.Security;
import java.util.Properties;

/**
 * MailConfiguration
 *
 * @author
 * @date 2019/11/27
 * @description
 */
@Configuration
public class MailConfiguration {

    private static final String FROM_MAIL_SMTP = "smtp.exmail.qq.com";
    private static final String FROM_MAIL_NAME = "monitor@honeytrip.cn";
    private static final String FROM_MAIL_PASS = "Honey#0430";

    @Bean
    public JavaMailSenderImpl JavaMailSender() {
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
        Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
        final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
        final Properties p = System.getProperties() ;
        //p.setProperty("mail.smtp.host", FROM_MAIL_SMTP);
        p.setProperty("mail.smtp.auth", "true");
        /*p.setProperty("mail.smtp.user", FROM_MAIL_NAME);
        p.setProperty("mail.smtp.pass", FROM_MAIL_PASS);*/
        p.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
        p.setProperty("mail.smtp.socketFactory.fallback", "false");
        //邮箱发送服务器端口,这里设置为465端口
        p.setProperty("mail.smtp.port", "465");
        p.setProperty("mail.smtp.socketFactory.port", "465");
        mailSender.setJavaMailProperties(p);
        mailSender.setPassword(FROM_MAIL_PASS);
        mailSender.setUsername(FROM_MAIL_NAME);
        mailSender.setHost(FROM_MAIL_SMTP);
        return mailSender;
    }

}
